#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "Sort.h"

int* ReadArr(int length)
{
	int* arrq = (int*)calloc(length, sizeof(int));
	for (int n = 0; n < length; n++)
	{
		arrq[n] = rand() % 100;
	}
	return arrq;
}

void PrintArr(int* arr, int length)
{
	for (int n = 0; n < length; n++)
	{
		printf("%d\n", arr[n]);
	}

}

typedef int(*sorter)(int* arr, int length);

void SortTest(int* arr, int length, sorter f, char* name)
{
	double start, finish, time;
	arr = ReadArr(length);
	start = clock();
	(*f)(arr, length);
	finish = clock();
	time = (finish - start) / 1000.0;
	free(arr);
	printf("%s\t%0.3f\n", name, time);


}

int main(int argc, char* args)
{
	double start, finish;
	double ShakerSort_t, BubbleSort_t, NaiveSort_t, Stdqsort_t;
	int* arr = NULL;
	int length;

	srand(time(NULL));

	while (1)
	{
		printf("Enter length of array ");
		scanf("%d", &length);
		printf("Elapsed time:\n");
		SortTest(arr, length, NaiveSort, "Naive Bubble Sort");
		SortTest(arr, length, qsort_common, "Std Qsort");
		SortTest(arr, length, ShakerSort_common, "Shaker Sort");
		SortTest(arr, length, sort, "Simple Sort");



		fflush(stdin);
		getc(stdin);
	}
	return 0;
}

